package com.yehongyu.mytools.network.httpclient;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;


public class GetUrl {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		GetUrl gu = new GetUrl();
		gu.moveSiteId1();
	}
	
	/**
	 * 批量升级扶植版（须订购）到标准版
	 */
	public void moveSiteId1() {
		//读取文件地址
		String filePath = "D:/checkPage/modify-moveSiteId1.txt";
		String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=moveSiteId1&userId=";
		String userId,backStr;
		int i=0,exception = 0,hasupdate=0,notorder=0,haserror=0,noneed=0,noshop=0;
		String postr = "success";	//升级成功
		String postr2 = "[not order,back to 4]";	//未订购不能升级
		String postr3 = "[not need movedata]";	//已经为标准版，不需要升级
		String postr4 = "[move error]";	//升级出错
		String postr5 = "[no shop]";	//找不到店铺
		BufferedReader file = null;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((userId = file.readLine()) != null) {
				i++;
				userId = userId.trim().toLowerCase();
				try {
					backStr = getHttpResponseAsString(url + userId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + userId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if (backStr.contains(postr)) {
					hasupdate++;
					System.out.println("当前操作记录：" + i + ",已有"+hasupdate+"用户ID为：" + userId 
							+ "的店铺升级成功！");
				} else if(backStr.contains(postr3)) {
					noneed++;
					System.out.println("当前操作记录：" + i + ",已有"+noneed+"个用户ID为：" + userId
							+ "的店铺已经为标准版，不需要升级！");
				} else if(backStr.contains(postr2)) {
					notorder++;
					System.out.println("当前操作记录：" + i + ",已有"+notorder+"个用户ID为：" + userId
							+ "的店铺未订购不能升级！");
				} else if(backStr.contains(postr4)) {
					haserror++;
					System.out.println("当前操作记录：" + i + ",已有"+haserror+"个用户ID为：" + userId
							+ "的店铺升级出错！");
				} else if(backStr.contains(postr5)) {
					noshop++;
					System.out.println("当前操作记录：" + i + ",已有"+noshop+"个用户ID为：" + userId
							+ "的店铺找不到！");
				} 
			}
			System.out.println("店铺升级成功:" + hasupdate);
			System.out.println("店铺已经为标准版，不需要升级:" + noneed);
			System.out.println("店铺未订购不能升级:" + notorder);
			System.out.println("店铺升级出错:" + haserror);
			System.out.println("店铺找不到:" + noshop);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	/**
	 * 修正C店铺站点ID
	 */
	public void onlyUpdateSiteId() {
		//读取文件地址
		String filePath = "D:/checkPage/modify-onlyUpdateSiteId.txt";
		String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=onlyUpdateSiteId&userId=";
		String userId,backStr;
		int i=0,exception = 0,hasupdate=0,haserror=0;
		String postr = "更新成功";	//更新成功
		String postr2 = "不需要更新";	//不需要更新
		BufferedReader file = null;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((userId = file.readLine()) != null) {
				i++;
				userId = userId.trim().toLowerCase();
				try {
					backStr = getHttpResponseAsString(url + userId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + userId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if (backStr.contains(postr)) {
					hasupdate++;
					System.out.println("当前操作记录：" + i + ",已有"+hasupdate+"用户ID为：" + userId 
							+ "的店铺更新成功！");
				} else if(backStr.contains(postr2)) {
					haserror++;
					System.out.println("当前操作记录：" + i + ",已有"+haserror+"个用户ID为：" + userId
							+ "的店铺不需要更新！");
				} 
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 升级扶植版旺铺
	 */
	public void updateBasicShop() {
		//读取文件地址
		String filePath = "D:/checkPage/updateBaiscShop.txt";
		String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=freeDataMove&userId=";
		String userId,backStr;
		int i=0,exception = 0,haserror=0, hasnotbasic=0,hasnotshop=0;
		String postr = "success";	//升级成功
		BufferedReader file = null;
//			File rsShopId = new File("D:/checkPage/rs-updateShop-ShopId.txt");
		try {
//				FileWriter fwShopId = new FileWriter(rsShopId);
			file = new BufferedReader(new FileReader(filePath));
			while ((userId = file.readLine()) != null) {
				i++;
				userId = userId.trim().toLowerCase();
				try {
					backStr = getHttpResponseAsString(url + userId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + userId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if (backStr.contains(postr)) {
					System.out.println("当前操作记录：" + i + ",用户ID为：" + userId 
							+ "的店铺升级成功！");
//						fwShopId.write("升级成功店铺ID为：" + shopId
//								+ "的店铺交流区页访问异常！\n");
				} else if(backStr.contains("[move error]")) {
					haserror++;
					System.out.println("当前操作记录：" + i + ",已有"+haserror+"个用户ID为：" + userId
							+ "的店铺升级失败！");
				} else if(backStr.contains("[not basic]")) {
					hasnotbasic++;
					System.out.println("当前操作记录：" + i + ",已有"+hasnotbasic+"个用户ID为：" + userId
							+ "的店铺为非扶植版旺铺！");
				} else if(backStr.contains("[no shop]")) {
					hasnotshop++;
					System.out.println("当前操作记录：" + i + ",已有"+hasnotshop+"个用户ID为：" + userId
							+ "的店铺找不到！");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void cleanShopCacheByUserId() {
		// 读取文件地址
		String filePath = "D:/checkPage/cleanShopCacheByUserId.txt";
		String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=cleanShopCacheOnly&userId=";
		String userId,backStr;
		int i=0,exception = 0,hasclear=0,hasclearfail=0;
		String postr = "清除店铺缓存成功！";	//清除店铺缓存成功
		BufferedReader file = null;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((userId = file.readLine()) != null) {
				i++;
				userId = userId.trim().toLowerCase();
				try {
					backStr = getHttpResponseAsString(url + userId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + userId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if(backStr.contains(postr)){
					hasclear++;
					System.out.println("当前操作记录：" + i + ",已有"+hasclear+"个用户ID为：" + userId 
							+ "的店铺缓存清除成功！");
				}else{
					hasclearfail++;
					System.out.println("当前操作记录：" + i + ",已有"+hasclearfail+"个用户ID为：" + userId
							+ "的店铺缓存清除失败！");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	public void getTopList() {
		// 读取文件地址
		String filePath = "D:/checkPage/verifyPageId.txt";
		BufferedReader file = null;
		// 写入文件地址
		File rsTowShopInfo = new File("D:/checkPage/rs-verifyPage-TopListFail.txt");
		try {
			FileWriter fwTowShopInfo = new FileWriter(rsTowShopInfo);
			file = new BufferedReader(new FileReader(filePath));
			String pageId = "";
			String backStr = "";
			int i = 0;
			int exception = 0;
			int hasinvalid = 0;
			String posdc = "<cms:module name=\"宝贝排行榜\" prototype=\"2040\">";
//			String posdb = "<cms:module name=\"宝贝排行榜\" prototype=\"1040\">";
			while ((pageId = file.readLine()) != null) {
				i++;
				pageId = pageId.trim();
				// System.out.println("当前操作记录：" + i + "");
				try {
					String url = "http://store.taobao.com/page/page_part.htm?id="
							+ pageId;
					backStr = getHttpResponseAsString(url);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常ID为：" + pageId + "-------" + i
							+ "×××检查出错数达到：" + exception);
					continue;
					// e.printStackTrace();
				}
				if (backStr.contains(posdc)/*||backStr.contains(posdb)*/) {
					hasinvalid++;
					System.out.println("当前操作记录：" + i + ",已有"+hasinvalid+"个页面ID为：" + pageId
							+ "的页面宝贝排行榜ID不存在！");
					fwTowShopInfo.write("页面ID为：" + pageId + "的页面宝贝排行榜ID不存在！\n");
				} else {
					System.out.println("当前操作记录：" + i + ",页面ID为：" + pageId
							+ "的页面正常！");
				}
			}
			fwTowShopInfo.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void importAndReleasedPage() {
		// 读取文件地址
		String filePath = "D:/checkPage/modify-importAndReleasePageId.txt";
		String pageId,backStr;
		int i=0,has=0,hasrel=0;
		String url = "http://store.taobao.com/page/admin_info.htm";
		String release = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=releasePage&pageId=";
		BufferedReader file;
		//写入文件地址
		File rsImport = new File("D:/checkPage/rs-modify-ImportFail.txt");
		File rsRelease = new File("D:/checkPage/rs-modify-ReleaseFail.txt");
		try {
			FileWriter fwImport = new FileWriter(rsImport);
			FileWriter fwRelease = new FileWriter(rsRelease);
			file = new BufferedReader(new FileReader(filePath));
			PostMethod method = new PostMethod(url);
			HttpClient client = new HttpClient();
			while ((pageId = file.readLine()) != null) {
				i++;
				pageId = pageId.trim();
				String content = getStringFromFile("D:/checkPage/"+ pageId + ".xml");
				// Create POST method , Set parameters on POST
				method = new PostMethod(url);
				method.addParameter("credit", "preDealData");
				method.addParameter("optype", "importPage");
				method.addParameter("pageId", pageId.trim());
				method.addParameter("content", content);
//				method.setRequestBody(pairs);
				method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "GBK");
				// method.addParameter(new NameValuePair("Blah", "Whoop2"));
				// Execute and print response
				client.executeMethod(method);
				backStr = method.getResponseBodyAsString();
				if(backStr.contains("XML内容覆盖成功！")){
					System.out.println("当前操作记录：" + i + ",页面ID："+pageId+"导入成功！");
				}else{
					has++;
					System.out.println("当前操作记录：" + i + ",已有"+has+"个页面ID："+pageId+"导入失败！");
					fwImport.write("页面ID为：" + pageId + "导入失败！\n");
					continue;
				}
				backStr = getHttpResponseAsString(release+pageId);
				if(backStr.contains("发布成功")){
					System.out.println("当前操作记录：" + i + ",页面ID："+pageId+"发布成功！");
				}else{
					hasrel++;
					System.out.println("当前操作记录：" + i + ",已有"+hasrel+"个页面ID："+pageId+"发布失败！");
					fwRelease.write("页面ID为：" + pageId + "发布失败！");
					continue;
				}
			}
			fwImport.close();
			fwRelease.close();
			method.releaseConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	//http://dsc04.daily.taobao.net:8883/shopsystem/T1JVdXXmaRt0MZcUfv.bulletin|var%5Ebulletin;sign^9aa00ae7b5956b353bf4b3dafe4dbc11;lang^gbk;t^1239673403000
	public void getBullentin() {
		// 读取文件地址
		String url = "http://dsc04.daily.taobao.net:8883/shopsystem/T1JVdXXmaRt0MZcUfv.bulletin%7Cvar%5Ebulletin;sign%5E9aa00ae7b5956b353bf4b3dafe4dbc11;lang%5Egbk;t%5E1239673403000";
		//写入文件地址
		try {
			PostMethod method = new PostMethod(url);
			HttpClient client = new HttpClient();
				// Create POST method , Set parameters on POST
			method = new PostMethod(url);
			client.executeMethod(method);
			String backStr = method.getResponseBodyAsString();
			System.out.println(backStr);
			method.releaseConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	

	/**
	 * 清除域名缓存
	 */
	public void clearDomainCache() {
			//读取文件地址
			String filePath = "D:/checkPage/cleanDomainCache.txt";
			String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=cleanShopDomain&domain=";
			String shopId,backStr;
			int i=0,exception = 0,has=0;
			String postr = "清除店铺缓存成功！";
			BufferedReader file = null;
			try {
				file = new BufferedReader(new FileReader(filePath));
				while ((shopId = file.readLine()) != null) {
					i++;
					shopId = shopId.trim().toLowerCase();
					System.out.println("当前操作记录：" + i);
					try {
						backStr = getHttpResponseAsString(url + shopId);
					} catch (Exception e) {
						exception++;
						System.out.println("获取异常,操作记录ID为：" + shopId
								+ "-------检查出错数达到：" + exception);
						continue;
					}
					if (backStr.contains(postr)||backStr.contains("根据店铺Id清除店铺域名缓存成功！")) {
						System.out.println("当前操作记录：" + i + ",店铺ID为：" + shopId 
								+ "的店铺清除缓存成功！");
					} else {
						has++;
						System.out.println("当前操作记录：" + i + ",已有"+has+"个店铺ID为：" + shopId
								+ "的店铺清除缓存失败！");
					}
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
	}

	private String getStringFromFile(String filePath) {
		StringBuffer out = new StringBuffer();
		try {
			InputStream in = new BufferedInputStream(new FileInputStream(
					filePath));
			byte[] b = new byte[4096];
			for (int n; (n = in.read(b)) != -1;) {
				out.append(new String(b, 0, n));
			}
		} catch (Exception e) {
			//
		}
		return out.toString();
	}
	
	/**
	 * 根据用户ID清除无店铺缓存标识
	 */
	public void getDomainUsed() {
		//读取文件地址
		String filePath = "D:/checkPage/domainUsed.txt";
		String domainStr,domain = "";
		BufferedReader file = null;
		int i=0;
		List<String> ourDomain = new ArrayList<String>();
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((domainStr = file.readLine()) != null) {
				i++;
				domain = "";
				domainStr = domainStr.split(" ")[0].trim();
				if(domainStr.endsWith("taobao.com")){
					domain = domainStr.substring(0, domainStr.indexOf("taobao.com"));
				}
//				System.out.println("当前操作记录：" + i + "===" + domain);
				if(!"".equals(domain)){
					if(domain.indexOf(".")!=domain.lastIndexOf(".")){
						domain = domain.substring(0,domain.length()-1);
						domain = domain.substring(domain.lastIndexOf(".")+1);
					}else if(domain.indexOf(".")==domain.lastIndexOf(".")){
						domain = domain.substring(0,domain.length()-1);
//						domain = domain.substring(domain.lastIndexOf("."));
					}
//					String[] d = domain.split(".");
//					domain = d[d.length-1];
//					System.out.println(domain);
					if(!ourDomain.contains(domain)){
						ourDomain.add(domain);
					}
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		String filePath1 = "D:/checkPage/b2cDomain.txt";
		String domainB2C;
		BufferedReader file1 = null;
		try {
			file1 = new BufferedReader(new FileReader(filePath1));
			while ((domainB2C = file1.readLine()) != null) {
				domainB2C = domainB2C.trim();
				if(ourDomain.contains(domainB2C)){
					System.out.println(domainB2C);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void getShopInfo(){
		//读取文件地址
		String filePath = "D:/checkPage/verifyPageId.txt";
		BufferedReader file = null;
		//写入文件地址
		File rsTowShopInfo = new File("D:/checkPage/rs-verifyPage-TowShopInfo.txt");
		File rsNoShopInfo = new File("D:/checkPage/rs-verifyPage-NoShopInfo.txt");
		File rsValidShopInfo = new File("D:/checkPage/rs-verifyPage-ValidShopInfo.txt");
		try {
			FileWriter fwTowShopInfo = new FileWriter(rsTowShopInfo);
			FileWriter fwNoShopInfo = new FileWriter(rsNoShopInfo);
			FileWriter fwValidShopInfo = new FileWriter(rsValidShopInfo);
			file = new BufferedReader(new FileReader(filePath));
			String pageId = "";
			String backStr = "";
			int i = 0;
			int exception = 0;
			int has = 0;
			int hasno = 0;
			int hasvalidp = 0;
			String posdh = "<cms:insertModule name=\"导航区域\"";
			String postr = "<cms:module name=\"掌柜档";
			String postrB2C = "<cms:module name=\"掌柜信息\"";
			long firstShopInfoPosition = 0;
			long lastShopInfoPosition = 0;
			while ((pageId = file.readLine()) != null) {
				i++;
				pageId = pageId.trim();
//				System.out.println("当前操作记录：" + i + "");
				try {
					String url = "http://store.taobao.com/page/page_part.htm?id="+pageId;
					backStr = getHttpResponseAsString(url);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常ID为：" + pageId
							+ "-------" + i + "×××检查出错数达到：" + exception);
					continue;
					// e.printStackTrace();
				}
				if(!backStr.contains(posdh)) {
					System.out.println("当前操作记录：" + i +",页面ID为：" + pageId
							+ "的页面不包含导航区域！");
					continue;	//不包含导航区域，则下一个。
				}
				
				firstShopInfoPosition = backStr.indexOf(postr);
				if(firstShopInfoPosition<0){
					firstShopInfoPosition = backStr.indexOf(postrB2C);
					if(firstShopInfoPosition>0){
						lastShopInfoPosition = backStr.lastIndexOf(postrB2C);
					}
				}else{
					lastShopInfoPosition = backStr.lastIndexOf(postr);
				}
				
				if (firstShopInfoPosition<0) {	//包含导航区域，却找不到掌柜档案
					hasno++;
					System.out.println("当前操作记录：" + i + ",已有"+hasno+"个页面ID为：" + pageId
							+ "的页面没有掌柜档案！");
					fwNoShopInfo.write("页面ID为：" + pageId
							+ "的页面没有掌柜档案！\n");
				} else if (lastShopInfoPosition!=firstShopInfoPosition) {
					has++;
					System.out.println("当前操作记录：" + i + ",已有"+has+"个页面ID为：" + pageId
							+ "的页面包含两个掌柜档案！");
					fwTowShopInfo.write("页面ID为：" + pageId
							+ "的页面包含两个掌柜档案！\n");
				}else {
					int insertModuleStart = backStr.indexOf(posdh);
					int firstModule = backStr.indexOf("<cms:module ",insertModuleStart);
					if(firstModule != firstShopInfoPosition){
						hasvalidp++;
						System.out.println("当前操作记录：" + i + ",已有"+hasvalidp+"个页面ID为：" + pageId
								+ "的页面掌柜档案位置不对！");
						fwValidShopInfo.write("页面ID为：" + pageId
								+ "的页面掌柜档案位置不对！\n");
					}else{
						System.out.println("当前操作记录：" + i + ",页面ID为：" + pageId
						+ "的页面正常！");
					}
				}
			}
			fwNoShopInfo.close();
			fwTowShopInfo.close();
			fwValidShopInfo.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void viewWangpu() {	//浏览旺铺
		//读取文件地址
		String filePath = "D:/checkPage/verifyShopId.txt";
		String shopId,backStr;
		int i=0,exception = 0;
		//校验URL
		String url = "http://store.taobao.com/shop/view_shop.htm?shop_id=";
		String urlsearch = "http://store.taobao.com/shop/view_shop.htm?search=y&shop_id=";
		String urlbbs = "http://store.taobao.com/shop/view_shop.htm?bbs=y&shop_id=";
		String urlservice = "http://store.taobao.com/shop/view_shop.htm?service=y&shop_id=";
		
		//返回值校验
		String postrold = "<div id=\"content\" class=\"eshop old\"";	//有老旺铺标志串
		String postrnew = "<div id=\"content\" class=\"eshop \"";	//有新旺铺标志串
		String postrark = "<div id=\"content\" class=\"eshop ark\"";	//有商城店铺标志串
		String postrsimple = "<div id=\"content\" class=\"eshop simple \"";	//有普通旺铺标志串
		String postrnoshop = "没有找到相应的店铺信息";	//无店铺标志串
		String postrnoshop2 = "浏览店铺必须指定店铺标识";	//无店铺标志串2
		String postrinvalid = "<div id=\"Page\" class=\"prosperous-shop\">";	//老的无效格式页面
		String postrnopagevm = "对不起，没有找到你所浏览的页面，请检查你输入的地址是否正确！";	//找不到页面信息
		String postrbbs = "<div class=\"shop-bbs single\">";	//交流区页串
		String postrsearch = "<div class=\"shop-hesper\">";	//搜索页串
		String postrservice = "<div class=\"shop-service\">";	//服务条款页串
		//写入文件地址
		File rsError = new File("D:/checkPage/rs-verifyShop-Error.txt");
		File rsNoshop = new File("D:/checkPage/rs-verifyShop-Noshop.txt");
		File rsUnkown = new File("D:/checkPage/rs-verifyShop-Unkown.txt");
		File rsNormal = new File("D:/checkPage/rs-verifyShop-Normal.txt");
		File rsWangpuOld = new File("D:/checkPage/rs-verifyShop-WangpuOld.txt");
		File rsWangpuArk = new File("D:/checkPage/rs-verifyShop-WangpuArk.txt");
		File rsWangpuNew = new File("D:/checkPage/rs-verifyShop-WangpuNew.txt");
		File rsWangpuInvalid = new File("D:/checkPage/rs-verifyShop-WangpuInvalid.txt");
		File rsWangpuCmsNull = new File("D:/checkPage/rs-verifyShop-WangpuCmsNull.txt");
		File rsWangpuSearchFail = new File("D:/checkPage/rs-verifyShop-WangpuSearchFail.txt");
		File rsWangpuBbsFail = new File("D:/checkPage/rs-verifyShop-WangpuBbsFail.txt");
		BufferedReader file = null;
		try {
			FileWriter fwNoshop = new FileWriter(rsNoshop);
			FileWriter fwError = new FileWriter(rsError);
			FileWriter fwUnkown = new FileWriter(rsUnkown);
			FileWriter fwNormal = new FileWriter(rsNormal);
			FileWriter fwWangpuInvalid = new FileWriter(rsWangpuInvalid);
			FileWriter fwWangpuCmsNull = new FileWriter(rsWangpuCmsNull);
			FileWriter fwWangpuOld = new FileWriter(rsWangpuOld);
			FileWriter fwWangpuArk = new FileWriter(rsWangpuArk);
			FileWriter fwWangpuNew = new FileWriter(rsWangpuNew);
			FileWriter fwWangpuSearchFail = new FileWriter(rsWangpuSearchFail);
			FileWriter fwWangpuBbsFail = new FileWriter(rsWangpuBbsFail);
			file = new BufferedReader(new FileReader(filePath));
			while ((shopId = file.readLine()) != null) {
				i++;
				shopId = shopId.trim();
				System.out.println("当前操作记录：" + i);
				try {
					backStr = getHttpResponseAsString(url + shopId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + shopId
							+ "-------检查出错数达到：" + exception);
					fwError.write("店铺ID为：" + shopId + "的店铺访问出错！\n");
					continue;
				}
				
				if (backStr.contains(postrinvalid)) {
					System.out.println("店铺ID为：" + shopId
							+ "的店铺访问失效,为无效格式旺铺页面！");
					fwWangpuInvalid.write("店铺ID为：" + shopId
							+ "的店铺访问失效,为无效格式旺铺页面！\n");
				} else if (backStr.contains(postrnopagevm)) {
					System.out.println("店铺ID为：" + shopId
							+ "的店铺访问失效,找不到页面信息！");
					fwWangpuCmsNull.write("店铺ID为：" + shopId
							+ "的店铺访问失效,找不到页面信息！\n");
				} else if (backStr.contains(postrnoshop)||backStr.contains(postrnoshop2))  {
					System.out.println("店铺ID为：" + shopId
							+ "的店铺访问为无店铺标识！");
					fwNoshop.write("店铺ID为：" + shopId
							+ "的店铺访问为无店铺标识！\n");
				} else if (backStr.contains(postrark)) {
					System.out.println("店铺ID为：" + shopId
							+ "的店铺访问成功,为商城店铺！");
					fwWangpuArk.write("店铺ID为：" + shopId
							+ "的店铺访问成功,为商城店铺！");
					try {
						backStr = getHttpResponseAsString(urlsearch+shopId);
						if (backStr.contains(postrsearch))  {
							System.out.println("商城店铺ID为：" + shopId
									+ "的店铺搜索页访问成功！");
							fwWangpuArk.write("店铺ID为：" + shopId
									+ "的店铺搜索页访问成功！");
						}else{
							System.out.println("商城店铺ID为：" + shopId
									+ "的店铺搜索页访问失败！");
							fwWangpuSearchFail.write("商城店铺ID为：" + shopId
									+ "的店铺搜索页访问失败！\n");
						}
					} catch (Exception e) {
						System.out.println("商城店铺ID为：" + shopId
								+ "的店铺搜索页访问异常！");
						fwWangpuSearchFail.write("商城店铺ID为：" + shopId
								+ "的店铺搜索页访问异常！\n");
					}
					try {
						backStr = getHttpResponseAsString(urlbbs+shopId);
						if (backStr.contains(postrbbs))  {
							System.out.println("商城店铺ID为：" + shopId
									+ "的店铺交流区页访问成功！");
							fwWangpuArk.write("商城店铺ID为：" + shopId
									+ "的店铺交流区页访问成功！");
						}else{
							System.out.println("商城店铺ID为：" + shopId
									+ "的店铺交流区页访问失败！");
							fwWangpuBbsFail.write("商城店铺ID为：" + shopId
									+ "的店铺交流区页访问失败！\n");
						}
					} catch (Exception e) {
						System.out.println("商城店铺ID为：" + shopId
								+ "的店铺交流区页访问异常！");
						fwWangpuBbsFail.write("商城店铺ID为：" + shopId
								+ "的店铺交流区页访问异常！\n");
					}
					try {
						backStr = getHttpResponseAsString(urlservice+shopId);
						if (backStr.contains(postrservice))  {
							System.out.println("商城店铺ID为：" + shopId
									+ "的店铺服务条款页访问成功！");
							fwWangpuArk.write("商城店铺ID为：" + shopId
									+ "的店铺服务条款页访问成功！");
						}else{
							System.out.println("商城店铺ID为：" + shopId
									+ "的店铺服务条款页访问失败！");
							fwWangpuBbsFail.write("商城店铺ID为：" + shopId
									+ "的店铺服务条款页访问失败！\n");
						}
					} catch (Exception e) {
						System.out.println("商城店铺ID为：" + shopId
								+ "的店铺服务条款页访问异常！");
						fwWangpuBbsFail.write("商城店铺ID为：" + shopId
								+ "的店铺服务条款页访问异常！\n");
					}
					fwWangpuArk.write("\n");
				} else if (backStr.contains(postrold)) {
					System.out.println("店铺ID为：" + shopId
							+ "的店铺访问成功,为老旺铺！");
					fwWangpuOld.write("店铺ID为：" + shopId
							+ "的店铺访问成功,为老旺铺！");
					try {
						backStr = getHttpResponseAsString(urlsearch + shopId);
						if (backStr.contains(postrsearch))  {
							System.out.println("老旺铺店铺ID为：" + shopId
									+ "的店铺搜索页访问成功！");
							fwWangpuOld.write("老旺铺店铺ID为：" + shopId
									+ "的店铺搜索页访问成功！");
						}else{
							System.out.println("老旺铺店铺ID为：" + shopId
									+ "的店铺搜索页访问失败！");
							fwWangpuSearchFail.write("店铺ID为：" + shopId
									+ "的店铺搜索页访问失败！\n");
						}
					} catch (Exception e) {
						System.out.println("老旺铺店铺ID为：" + shopId
								+ "的店铺搜索页访问异常！");
						fwWangpuSearchFail.write("老旺铺店铺ID为：" + shopId
								+ "的店铺搜索页访问异常！\n");
					}
					try {
						backStr = getHttpResponseAsString(urlbbs + shopId);
						if (backStr.contains(postrbbs))  {
							System.out.println("老旺铺店铺ID为：" + shopId
									+ "的店铺交流区页访问成功！");
							fwWangpuOld.write("店铺ID为：" + shopId
									+ "的店铺交流区页访问成功！");
						}else{
							System.out.println("老旺铺店铺ID为：" + shopId
									+ "的店铺交流区页访问失败！");
							fwWangpuBbsFail.write("老旺铺店铺ID为：" + shopId
									+ "的店铺交流区页访问失败！\n");
						}
					} catch (Exception e) {
						System.out.println("老旺铺店铺ID为：" + shopId
								+ "的店铺交流区页访问异常！");
						fwWangpuBbsFail.write("老旺铺店铺ID为：" + shopId
								+ "的店铺交流区页访问异常！\n");
					}
					fwWangpuOld.write("\n");
				} else if (backStr.contains(postrnew)) {
					System.out.println("店铺ID为：" + shopId
							+ "的店铺访问成功,为新旺铺！");
					fwWangpuNew.write("店铺ID为：" + shopId
							+ "的店铺访问成功,为新旺铺！");
					try {
						backStr = getHttpResponseAsString(urlsearch + shopId);
						if (backStr.contains(postrsearch))  {
							System.out.println("新旺铺店铺ID为：" + shopId
									+ "的店铺搜索页访问成功！");
							fwWangpuNew.write("新旺铺店铺ID为：" + shopId
									+ "的店铺搜索页访问成功！");
						}else{
							System.out.println("新旺铺店铺ID为：" + shopId
									+ "的店铺搜索页访问失败！");
							fwWangpuSearchFail.write("新旺铺店铺ID为：" + shopId
									+ "的店铺搜索页访问失败！\n");
						}
					} catch (Exception e) {
						System.out.println("新旺铺店铺ID为：" + shopId
								+ "的店铺搜索页访问异常！");
						fwWangpuSearchFail.write("新旺铺店铺ID为：" + shopId
								+ "的店铺搜索页访问异常！\n");
					}
					try {
						backStr = getHttpResponseAsString(urlbbs + shopId);
						if (backStr.contains(postrbbs))  {
							System.out.println("新旺铺店铺ID为：" + shopId
									+ "的店铺交流区页访问成功！");
							fwWangpuNew.write("新旺铺店铺ID为：" + shopId
									+ "的店铺交流区页访问成功！");
						}else{
							System.out.println("新旺铺店铺ID为：" + shopId
									+ "的店铺交流区页访问失败！");
							fwWangpuBbsFail.write("新旺铺店铺ID为：" + shopId
									+ "的店铺交流区页访问失败！\n");
						}
					} catch (Exception e) {
						System.out.println("新旺铺店铺ID为：" + shopId
								+ "的店铺交流区页访问异常！");
						fwWangpuBbsFail.write("新旺铺店铺ID为：" + shopId
								+ "的店铺交流区页访问异常！\n");
					}
					fwWangpuNew.write("\n");
				} else if (backStr.contains(postrsimple)) {
					System.out.println("店铺ID为：" + shopId
							+ "的店铺访问成功,为普通店铺！");
					fwNormal.write("店铺ID为：" + shopId
							+ "的店铺访问成功,为普通店铺！\n");
				} else {
					System.out.println("店铺ID为：" + shopId
							+ "的店铺访问失败，内容未知！");
					fwUnkown.write("店铺ID为：" + shopId
							+ "的店铺访问失败，内容未知！内容如下：\n" + backStr + "\n");
				}
			}
			fwNoshop.close();
			fwError.close();
			fwUnkown.close();
			fwNormal.close();
			fwWangpuInvalid.close();
			fwWangpuCmsNull.close();
			fwWangpuOld.close();
			fwWangpuArk.close();
			fwWangpuNew.close();
			fwWangpuSearchFail.close();
			fwWangpuBbsFail.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 根据用户ID清除无店铺缓存标识
	 */
	public void cleanNoshopCacheByUserId() {
		//读取文件地址
		String filePath = "D:/checkPage/cleanNoshopCacheByUserId.txt";
		String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=cleanNoShopCacheByUserId&userId=";
		String userId,backStr;
		int i=0,exception = 0,has=0;
		String postr = "根据用户ID清除无店铺缓存成功！";
		BufferedReader file = null;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((userId = file.readLine()) != null) {
				i++;
				userId = userId.trim();
				System.out.println("当前操作记录：" + i);
				try {
					backStr = getHttpResponseAsString(url + userId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + userId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if (backStr.contains(postr)) {
					System.out.println("当前操作记录：" + i + ",用户ID为：" + userId 
							+ "的无店铺标识清除缓存成功！");
				} else {
					has++;
					System.out.println("当前操作记录：" + i + ",已有"+has+"个用户ID为：" + userId
							+ "的无店铺标识清除缓存失败！");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 根据店铺ID清除店铺缓存
	 */
	public void cleanShopCache() {
		//读取文件地址
		String filePath = "D:/checkPage/cleanShopCache.txt";
		String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=cleanShopCache&shopId=";
		String shopId,backStr;
		int i=0,exception = 0,has=0;
		String postr = "清除店铺缓存成功！";
		BufferedReader file = null;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((shopId = file.readLine()) != null) {
				i++;
				shopId = shopId.trim();
				System.out.println("当前操作记录：" + i);
				try {
					backStr = getHttpResponseAsString(url + shopId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + shopId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if (backStr.contains(postr)||backStr.contains("的对象不存在")) {
					System.out.println("当前操作记录：" + i + ",店铺ID为：" + shopId 
							+ "的店铺清除缓存成功！");
				} else {
					has++;
					System.out.println("当前操作记录：" + i + ",已有"+has+"个店铺ID为：" + shopId
							+ "的店铺清除缓存失败！");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 根据店铺ID初始化店铺
	 */
	public void initShop() {
		//读取文件地址
		String filePath = "D:/checkPage/modify-initShopId.txt";
		String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=initShop&shopId=";
		String shopId,backStr;
		int i=0,exception = 0,has=0;
		String postr = "初始化成功！";
		BufferedReader file = null;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((shopId = file.readLine()) != null) {
				i++;
				shopId = shopId.trim();
				System.out.println("当前操作记录：" + i);
				try {
					backStr = getHttpResponseAsString(url + shopId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + shopId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if (backStr.contains(postr)) {
					System.out.println("当前操作记录：" + i + ",店铺ID为：" + shopId 
							+ "的店铺初始化成功！");
				} else {
					has++;
					System.out.println("当前操作记录：" + i + ",已有"+has+"个店铺ID为：" + shopId
							+ "的店铺初始化失败！");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 根据店铺ID切回200旺铺
	 */
	public void rollBack200() {
		//读取文件地址
		String filePath = "D:/checkPage/modify-rollBack200ShopId.txt";
		String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=rollbackTo200&shopId=";
		String shopId,backStr;
		int i=0,exception = 0,has=0;
		String postr = "回到200旺铺成功！";
		BufferedReader file = null;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((shopId = file.readLine()) != null) {
				i++;
				shopId = shopId.trim();
				System.out.println("当前操作记录：" + i);
				try {
					backStr = getHttpResponseAsString(url + shopId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + shopId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if (backStr.contains(postr)) {
					System.out.println("当前操作记录：" + i + ",店铺ID为：" + shopId 
							+ "的店铺回到200旺铺成功！");
				} else {
					has++;
					System.out.println("当前操作记录：" + i + ",已有"+has+"个店铺ID为：" + shopId
							+ "的店铺回到200旺铺失败！");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 根据ID重新发布页面
	 */
	public void republishPageFromReleasedXml() {
		//读取文件地址
		String filePath = "D:/checkPage/modify-republishPageId.txt";
		String url = "http://store.taobao.com/page/republish_xml_content.htm?pageId=";
		String pageId,backStr;
		int i=0,exception = 0,has=0;
		String postr = "重新发布失败";
		BufferedReader file = null;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((pageId = file.readLine()) != null) {
				i++;
				pageId = pageId.trim();
				System.out.println("当前操作记录：" + i);
				try {
					backStr = getHttpResponseAsString(url + pageId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + pageId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if (!backStr.contains(postr)) {
					System.out.println("当前操作记录：" + i + ",页面ID为：" + pageId 
							+ "的页面重新发布成功！");
				} else {
					has++;
					System.out.println("当前操作记录：" + i + ",已有"+has+"个页面ID为：" + pageId
							+ "的页面重新发布失败！");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 根据ID发布页面
	 */
	public void releasePage() {
		//读取文件地址
		String filePath = "D:/checkPage/modify-releasePageId.txt";
		String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=releasePage&pageId=";
		String pageId,backStr;
		int i=0,exception = 0,has=0;
		String postr = "发布成功";
		BufferedReader file = null;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((pageId = file.readLine()) != null) {
				i++;
				pageId = pageId.trim();
				System.out.println("当前操作记录：" + i);
				try {
					backStr = getHttpResponseAsString(url + pageId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + pageId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if (backStr.contains(postr)) {
					System.out.println("当前操作记录：" + i + ",页面ID为：" + pageId 
							+ "的页面发布成功！");
				} else {
					has++;
					System.out.println("当前操作记录：" + i + ",已有"+has+"个页面ID为：" + pageId
							+ "的页面发布失败！");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 根据ID删除页面
	 */
	public void deletePage() {
		//读取文件地址
		String filePath = "D:/checkPage/modify-deletePageId.txt";
		String url = "http://store.daily.taobao.net/page/admin_info.htm?credit=preDealData&optype=deletePage&pageId=";
		String pageId,backStr;
		int i=0,exception = 0,has=0;
		String postr = "删除页面成功！";
		BufferedReader file;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((pageId = file.readLine()) != null) {
				i++;
				pageId = pageId.trim();
				System.out.println("当前操作记录：" + i);
				try {
					backStr = getHttpResponseAsString(url + pageId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + pageId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if (backStr.contains(postr)) {
					System.out.println("当前操作记录：" + i + ",页面ID为：" + pageId
							+ "的页面删除成功！");
				} else {
					has++;
					System.out.println("当前操作记录：" + i + ",已有"+has+"个页面ID为：" + pageId
							+ "的页面删除失败！");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 根据ID撤回页面
	 */
	public void revertPage() {
		// 读取文件地址
		String filePath = "D:/checkPage/modify-revertPageId.txt";
		String url = "http://store.taobao.com/page/admin_info.htm?credit=preDealData&optype=revertPage&pageId=";
		String pageId,backStr;
		int i=0,exception = 0,has=0;
		String postr = "XML内容回滚成功";
		BufferedReader file;
		try {
			file = new BufferedReader(new FileReader(filePath));
			while ((pageId = file.readLine()) != null) {
				i++;
				pageId = pageId.trim();
				System.out.println("当前操作记录：" + i);
				try {
					backStr = getHttpResponseAsString(url + pageId);
				} catch (Exception e) {
					exception++;
					System.out.println("获取异常,操作记录ID为：" + pageId
							+ "-------检查出错数达到：" + exception);
					continue;
				}
				if(backStr.contains(postr)){
					System.out.println("当前操作记录：" + i + ",页面ID为：" + pageId
							+ "回滚成功！");
				}else{
					has++;
					System.out.println("当前操作记录：" + i + ",已有"+has+"个页面ID为：" + pageId
							+ "回滚失败！");
//					System.out.println("页面ID："+pageId.trim()+"回滚失败！");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static String getHttpResponseAsString(String url) throws Exception {
		// try{
		// HttpClient httpClient = new HttpClient();
		// GetMethod getMethod = new GetMethod(url);
		//			
		// int statusCode;
		// statusCode = httpClient.executeMethod(getMethod);
		//
		// if(statusCode == HttpStatus.SC_OK){
		// return
		// inputStream2String2(getMethod.getResponseBodyAsStream());//.getResponseBodyAsString();
		// }else{
		// throw new
		// Exception("[DefaultWuiManager]getHttpResponseAsString: can not get http response!");
		// }
		// }catch (Exception e) {
		// throw new
		// Exception("[DefaultWuiManager]getHttpResponseAsString: "+e);
		// }

		StringBuffer out = new StringBuffer();
		try {
			InputStream in = new BufferedInputStream(new URL(url).openStream());
			byte[] b = new byte[20480];
			for (int n; (n = in.read(b)) != -1;) {
				out.append(new String(b, 0, n));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return out.toString();
	}

	public String inputStream2String(InputStream in) throws IOException {
		StringBuffer out = new StringBuffer();
		byte[] b = new byte[4096];
		for (int n; (n = in.read(b)) != -1;) {
			out.append(new String(b, 0, n));
		}
		return out.toString();
	}

	public static String inputStream2String2(InputStream is) throws IOException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		int i = -1;
		while ((i = is.read()) != -1) {
			baos.write(i);
		}
		return baos.toString();
	}
}

